package com.system.healthproject.model.sickuser.service.imp;

import com.system.healthproject.bean.PagesBean;
import com.system.healthproject.mapper.DiseaseLogMapper;
import com.system.healthproject.model.sickuser.service.DiseaseLogService;
import com.system.healthproject.pojo.DiseaseLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DiseaseLogServiceImp implements DiseaseLogService {

    @Autowired
    DiseaseLogMapper diseaseLogMapper;


    @Override
    public Boolean addDiseaseLog(DiseaseLog diseaseLog, Integer loginId) {
        diseaseLog.setLoginId(loginId);
        int insert = diseaseLogMapper.insert(diseaseLog);
        return insert==1;
    }

    @Override
    public PagesBean<Map<String, Object>> getDiseaseLogList(int page, int size, Integer loginId) {
        PagesBean<Map<String, Object>> mapPagesBean = new PagesBean<>();

        List<Map<String, Object>> diseaseLogList =
                diseaseLogMapper.getDiseaseLogList((page - 1) * size, size, loginId);
        int total = diseaseLogMapper.getTotal(loginId);
        mapPagesBean.setNowsPage(page);
        mapPagesBean.setPageSize(size);
        mapPagesBean.setData(diseaseLogList);
        mapPagesBean.setDataCount(total);
        return mapPagesBean;
    }
}
